/*修改按钮*/
let change=document.getElementsByClassName("change");
/*删除按钮*/
let deleteUser=document.getElementsByClassName("delete");
/*弹窗*/
let popupWindow=document.getElementsByClassName("popupWindow");
let userNameS=document.getElementsByClassName("userNameS");
let mask=document.getElementsByClassName("mask")[0];
/*点击删除*/
for(let i=0;i<deleteUser.length;i++){
    /*点击修改或删除按钮弹出弹窗*/
    deleteUser[i].onclick=function(){
        mask.style.display="block";
        popupWindow[i].style.display="block";
        userNameS[i].innerHTML=allTd[i*11+2].innerHTML;
    }
}
/*取消按钮*/
let cancel=document.getElementsByClassName("cancel");
/*确定按钮*/
let determine=document.getElementsByClassName("determine");

let allTd=document.getElementsByTagName("td");
/*点击确定或取消按钮弹窗消失*/
for(let i=0;i<cancel.length;i++){
    cancel[i].onclick=function(){
        mask.style.display="none";
        popupWindow[i].style.display="none";
    }
}
for(let i=0;i<determine.length;i++){
    determine[i].onclick=function(){
        mask.style.display="none";
        popupWindow[i].style.display="none";
    }
}

let lookUp=document.getElementsByClassName("lookUp");
let lookUpPop=document.getElementsByClassName("lookUpPop");
let lookUpCut=document.getElementsByClassName("lookUpCut");
for(let i=0;i<lookUp.length;i++){
    lookUp[i].onclick=function(){
        mask.style.display="block";
        lookUpPop[i].style.display="block";
        // for(let j=0;j<allTd.length;j++){
        //     popInput[j].value=allTd[j].innerHTML;
        // }
    }
    lookUpCut[i].onclick=function(){
        mask.style.display="none";
        lookUpPop[i].style.display="none";
    }
}
//搜索
let selectBtn=document.getElementById("selectBtn");
selectBtn.onclick=function(){
    $.ajax({
        url:"http://localhost:8080/final_kele_war_exploded/blogs/findByTitle",
        type:get,
        data:{

        }
    })
}
//批量删除
let batchDelete=document.getElementsByClassName("batchDelete")[0];
let tbody=document.getElementsByClassName("tbody")[0];
let successDelete=document.getElementsByClassName("successDelete")[0]
let allTr=tbody.getElementsByTagName("tr");
batchDelete.onclick=function(){
    let userTable=document.getElementById("userTable");
    let allTh=userTable.getElementsByTagName("th");

    allTh[0].style.display="block";
    successDelete.style.display="block";
    console.log(allTr.length)
    console.log(allTd.length)
    for(let j=0;j<allTr.length;j++){
        allTd[j*11].style.display="block";
        allTd[j*11].style.border="0";
    }
}
//批量删除
successDelete.onclick = function () {
    //获取选中的复选框
    let checkBox = document.getElementsByClassName("checkBox");
    var arr = [];
    for (let i = 0; i < allTr.length; i++) {
        if (checkBox[i].checked == true) {
            arr.push(allTd[i * 11 + 1].innerHTML);
            console.log(allTd[i * 11 + 1].innerHTML)
        }
    }
    var b=" ";
    for (let i in arr){
        b+=arr[i]
        if(i==arr.length-1){
            break
        }
        b+='%2C'
    }
    if(arr.length==0){
        alert("您还未选择需批量删除的文章")
    }else{
        var Confirm = confirm("确定删除这些用户吗");
        if (Confirm == true) {
            $.ajax({
                url: "../blog/deleteArray?bids=" + b,
                type: "delete",
                // data:{
                //     ids:10,
                //     // ids:JSON.stringify(arr).replace(/[\[\]]/g,''),
                // },
                success: function (data) {
                    if (data.msg == "删除成功") {
                        alert("删除成功");
                        window.location.reload();
                    } else {
                        console.log(data)
                    }
                }
            })
        } else {

        }
    }

}
//重置刷新页面
let resetting=document.getElementsByClassName("resetting")[0];
resetting.onclick=function(){
    window.location.reload();
}
// let tbody=document.getElementsByClassName("tbody")[0];
// let allTr=tbody.getElementsByTagName("tr");
// let allTd=allTr.getElementsByTagName("td");
// for(let i=0;i<allTr.length;i++){
//     for(let j=0;j<allTd.length;j++){
//         // if(allTd[j].innerHTML[0]==="生"){
//         //     articleTitle.innerHTML+='<span>生活</span>'
//         // }
//     }
// }
//
// if(BlogType.innerHTML[0]==="生"){
//     articleTitle.innerHTML+='<span>生活</span>'
// }
// if(BlogType.innerHTML[2]==="二"){
//     articleTitle.innerHTML+='<span>二次元</span>'
// }
// if(BlogType.innerHTML[4]==="音"){
//     articleTitle.innerHTML+='<span>音乐</span>'
// }
// if(BlogType.innerHTML[6]==="美"){
//     articleTitle.innerHTML+='<span>美食</span>'
// }
// if(BlogType.innerHTML[8]==="影"){
//     articleTitle.innerHTML+='<span>影视</span>'
// }
// if(BlogType.innerHTML[10]==="运"){
//     articleTitle.innerHTML+='<span>运动</span>'
// }
// if(BlogType.innerHTML[12]==="科"){
//     articleTitle.innerHTML+='<span>科技</span>'
// }
// if(BlogType.innerHTML[14]==="技"){
//     articleTitle.innerHTML+='<span>技术</span>'
// }
// if(BlogType.innerHTML[16]==="社"){
//     articleTitle.innerHTML+='<span>社交</span>'
// }
// if(BlogType.innerHTML[18]==="其"){
//     articleTitle.innerHTML+='<span>其他</span>'
// }
